package com.WFinstitute.serviceImpl;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.WFinstitute.domain.Scholar;
import com.WFinstitute.repository.ScholarRepository;
import com.WFinstitute.service.ScholarService;
import com.WFinstitute.util.Page;

/**
 * 
 * @author 匹夫
 * @date 2016-7-28 下午8:25:10
 * @function
 */
@Service
public class ScholarServiceImpl implements ScholarService{
	@Resource
	private ScholarRepository  scholarRepository;

	@Override
	public Scholar addScholar(Scholar scholar) {
		return scholarRepository.save(scholar);
	}

	@Override
	public Page<Scholar> findScholarList(Integer pageSize, Integer pageIndex,String name) {
		String jpql="select n from Scholar n";
		return scholarRepository.getAllPage(jpql, null, pageSize, pageIndex);
	}

	@Override
	public long count() {
		return scholarRepository.count();
	}

	@Override
	public Scholar updateScholar(Scholar scholar) {
		 return (Scholar)scholarRepository.update(scholar);
	}

	@Override
	public Scholar findScholarById(Integer id) {
		return scholarRepository.findOne(id);
	}

	@Override
	public void deleteScholarById(Integer id) {
		scholarRepository.delete(id);
	}

	@Override
	public List<Scholar> findScholarList() {
		return scholarRepository.findAll();
	}

	@Override
	public Scholar findScholarByName(String name) {
		return scholarRepository.findScholarByName(name);
	}



}
